package com.hnqcgczy.controller;

import com.hnqcgczy.service.IProductService;
import com.hnqcgczy.service.impl.ProductServiceImpl;
import com.hnqcgczy.vo.TProduct;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productDetail")
public class ProductDetailServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取商品编号
        String tpId=req.getParameter("tpId");
        //2:创建商品服务对象
        IProductService productService=new ProductServiceImpl();
        //3: 获取商品
        TProduct product=productService.getProductById(Integer.parseInt(tpId));
        //4:存储request作用域
        req.setAttribute("product",product);
        //5:转发到详情页JSP
        req.getRequestDispatcher("/productDetail.jsp").forward(req,resp);
    }
}
